package com.nulldev.util.web.nTube.pages.invidious_compat;

import com.nulldev.util.languages.json.uniapi.UniJsonValue;
import com.nulldev.util.web.HttpServer3.Response;
import com.nulldev.util.web.HttpServer3.pages.v3.HttpPage3;
import com.nulldev.util.web.nTube.NTubeServer;

public class APIStats extends HttpPage3 {

	public APIStats() {
		super("/api/v1/stats");
		this.setCachingMethod(CachingMethod.VERY_SHORT_CACHE);
		this.setChecks(EnhancedSecurityChecks.DISALLOW_POST_DATA, EnhancedSecurityChecks.ONLY_ALLOW_BASIC_METHODS);
	}

	@SuppressWarnings("resource")
	@Override
	public Response onRequest(final Request request) {
		final UniJsonValue v = UniJsonValue.object();
		v.add("version", "0.0.1");
		v.add("openRegistrations", false);
		final UniJsonValue software = UniJsonValue.object(4);
		software.add("name", "invidious");
		software.add("nameLongString", "nTube on Invidious");
		software.add("version", NTubeServer.nTube_VERSION.asVersionString());
		software.add("branch", NTubeServer.DEVELOPMENT_BUILD ? "dev" : "stable");
		v.add("software", software);
		final UniJsonValue usage = UniJsonValue.object(1);
		final UniJsonValue users = UniJsonValue.object(3);
		users.add("total", 0);
		users.add("activeHalfyear", 0);
		users.add("activeMonth", 0);
		usage.add("users", users);
		v.add("usage", usage);
		final UniJsonValue metadata = UniJsonValue.object(2);
		metadata.add("updatedAt", System.currentTimeMillis());
		metadata.add("lastChannelRefreshedAt", -1L);
		v.add("metadata", metadata);
		return new Response(200, v, v).setCustomMime("application/json");
	}
}
